package com.groovy

import java.sql.ResultSet

class DBUtils {

    static List<String> getTableNames(sql, schema) {
        List<String> list = new ArrayList();
        ResultSet rs = sql.getConnection().getMetaData().getTables(null, schema, "SYS_USER_%", null)
        while (rs.next()) {
            int n = 1;
            list.add(rs.getString(3))
        }
        return list;
    }

    static List<DBColumnVO> getColumn(sql, schema, table) {
        ResultSet rs = sql.getConnection().getMetaData().getColumns(null, "%", table.toUpperCase(), "%");
        List<DBColumnVO> list = []
        while (rs.next()) {
            DBColumnVO dbColumnVO = new DBColumnVO();
            dbColumnVO.comments = rs.getString("REMARKS");

            dbColumnVO.columnName = rs.getString("COLUMN_NAME");
            dbColumnVO.columnType = rs.getInt("DATA_TYPE");
            dbColumnVO.columnTypeName = rs.getString("TYPE_NAME");
            // COLUMN_SIZE
            //dbColumnVO.javaName = getJavaName(dbColumnVO.columnName);
            //dbColumnVO.javaTypeName = getJavaTypeName(dbColumnVO.columnType, dbColumnVO.columnTypeName);
            list.add(dbColumnVO);
//			println dbColumnVO.columnName+","+dbColumnVO.comments
        }

        return list;
    }
}

class DBColumnVO {
    def columnName;
    def columnType;
    def columnTypeName;
    def javaTypeName;
    def javaName;
    def comments = "";
}


